package org.poker.swing;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.Action;

public class KeyControl implements KeyListener {

	private Action[] actions;
	
	public KeyControl(Action[] actions) {
		this.actions = actions;
	}
	
	public void keyPressed(KeyEvent e) {
	}

	public void keyReleased(KeyEvent e) {
	}

	public void keyTyped(KeyEvent e) {
    	ActionEvent e1 = null;
    	int charId = e.getKeyChar();
    	if(charId>='1'&&charId<='5') {
    		e1 = new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, "carta_"+e.getKeyChar(), e.getWhen(), e.getModifiers());
    		this.actions[0].actionPerformed(e1);
    	} else if (e.getKeyChar()=='t' || e.getKeyChar()=='-') {
    		e1 = new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, null, e.getWhen(), e.getModifiers());
    		this.actions[1].actionPerformed(e1);
    	} else if (e.getKeyChar() =='n' || e.getKeyChar()=='=') {
    		e1 = new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, null, e.getWhen(), e.getModifiers());
    		this.actions[2].actionPerformed(e1);
    	}
	}
}
